Skip to content

fix(web): collapse a first child's top margin through its block; stop counting ::marker as an element - #851

Merged
ormastes merged 1 commit into
mainfrom
work/web-parity-round7-2026-09-13
Sep 13, 2026
Merged

ormastes merged 1 commit into
mainfrom
work/web-parity-round7-2026-09-13

Conversation

@ormastes

Copy link
Copy Markdown
Owner

Chrome-parity round 7 for the pure-Simple web renderer. Two layout/keying
defects closed, each with a sabotage-proven spec; two items re-confirmed
blocked and recorded rather than worked around.

1. First-child TOP margin collapse-through (CSS 2.2 §8.3.1, leading half)

Round 6 closed the trailing half (LayoutResult.trailing_margin_b). The
leading half could not use the same shape: the caller advances cy by
collapse_margins_signed(prev_margin_b, cst.margin_t) before
layout_with_style runs, so the first child's effective top margin is unknown
when the parent's origin is fixed.

Resolved with the two-phase mechanics offset_layout_subtree already serves
elsewhere, not with a pre-pass: the child is placed from its declared
margin-top, then the child subtree is re-offset by the difference against its
effective one (collapse(declared, child.leading_margin_t)). When the block
itself collapses its top through, the whole effective margin is pulled back out,
the height shrinks by it, and it is returned as this block's leading_margin_t
for its own parent — so N nested wrappers yield ONE margin, not one per level.
block_top_margin_collapses_through mirrors the bottom half's exclusion set
exactly (documents, non-block display, out-of-flow, floats, BFC roots, widget
panels, flex/grid items, and conservatively every height clamp).

Chrome oracle, heights in px: <div><p>t</p></div> 24 (was 40),
padding-bottom:10px 50 (was 66), border-bottom:2px 42 (was 58); the cases
that must NOT collapse (top padding, overflow:hidden, explicit height) are
unchanged.

2. ::marker counted as a DOM element in the renderer's nth-path keys

The geometry differ stopped counting ::marker boxes on 2026-09-12. The
renderer's own copy of the same scheme, _simple_web_layout_element, did not —
while the Chrome walker's comment claims the two mirror each other
"byte-for-byte". Since the marker is every <li>'s FIRST child by construction,
every hit-test and CSS-animation target key inside a list item was off by one
ordinal, i.e. addressed the wrong node. All three copies now exclude
::-prefixed tags.

Specs (both required by .claude/rules/testing.md)

  • test/01_unit/browser_engine/first_child_top_margin_collapse_spec.spl — 10 AC:
    3 reproducing the oracle rows, 7 generalizing (non-collapsing cases, the
    escaped margin still separating the block, double nesting, a <li> whose
    ::marker is its first node, an out-of-flow first child).
  • test/01_unit/browser_engine/li_marker_nth_path_key_spec.spl — 3 AC on the
    target-key scheme.

Sabotage triples recorded in the bug files: forcing
block_top_margin_collapses_through false fails AC-1/2/3/8 and leaves AC-4..7
green; swapping the "::" prefix for one no tag starts with fails AC-1/2 and
leaves AC-3 green.

Measurement

Geometry differ, GEOM_DIFF_HEIGHT=20000, both sides run in the same
worktree with the same binary
(.claude/rules/testing.md § Measurement
traps — the before side is the same tree with only the two lib files checked
out at HEAD~1):

page compared mismatched BEFORE mismatched AFTER
css-layout 376 359 359
animation 81 79 79

No movement on either page, and css-layout.geometry_diff.md is byte-identical
between the runs. That is a real result rather than a failed measurement: the
collapse-through predicate excludes flex/grid items and any parent with top
padding or a border, which is what these card-based demo pages are built from.
The fixes are pinned by the oracle-backed specs, not by these pages.

The PIXEL differ could not be used on this macOS host: Chrome hits the 90 s
screenshot alarm on every page and one html Simple render had not finished
after 20 minutes, in both lib states. Stated rather than substituted with
numbers measured elsewhere.

Not fixed, recorded

  • bold advances — re-verified on this host: assets/fonts holds one static bold
    face tree-wide (a blackletter display face) and the sans candidate list is
    otherwise variable fonts plus Linux paths absent on macOS. Adding the weight
    argument first would change no advance.
  • <li> reparented under <section>, which is what actually desyncs the
    geometry report on html; narrowed by one step (the emitter copies
    nodes[i].parent, so it does not invent the parent) but the root is NOT
    established — two candidates named in the record.
  • tables (table_layout_spec 0/7) — untouched, multi-hour.
  • ifc_linebox_spec is 0/10 and fails identically with the two lib files
    reverted: pre-existing, not caused here.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TVraTPgGDVypESTsVqXPgi

… counting ::marker as an element

CSS 2.2 §8.3.1 leading half. Round 6 closed the trailing half with
LayoutResult.trailing_margin_b, which works because the margin is known after
the children are laid out. The leading half cannot use that shape: the caller
advances cy by collapse_margins_signed(prev_margin_b, cst.margin_t) BEFORE
layout_with_style runs.

Resolved with the two-phase mechanics offset_layout_subtree already serves
elsewhere rather than a pre-pass: the block child is placed from its DECLARED
margin-top, then its subtree is re-offset by the difference against its
EFFECTIVE one, collapse(declared, child.leading_margin_t). When the block itself
collapses its top through, the whole effective margin is pulled back out, the
height shrinks by it, and it is returned as this block's leading_margin_t for
its own parent — so N nested wrappers yield ONE margin, not one per level. The
<body> hand-rolled case in the same loop now uses the effective margin too.
block_top_margin_collapses_through mirrors the bottom half's exclusion set
exactly, height clamps included: CSS lets a top margin escape a fixed-height
block, but admitting that here would move boxes the trailing half still holds,
so it stays conservative and the remaining case is recorded.

Chrome oracle, heights: <div><p>t</p></div> 24 (was 40), padding-bottom:10px 50
(was 66), border-bottom:2px 42 (was 58).

Second, unrelated-looking but the same family: _simple_web_layout_element did
not skip ::marker, which the foundation pass synthesises as every <li>'s FIRST
child. The geometry differ stopped counting marker boxes on 2026-09-12; the
renderer's own copy of the scheme did not, while the Chrome walker's comment
claims the two mirror each other byte-for-byte. Every hit-test and
CSS-animation target key inside a list item was off by one ordinal. All three
copies now exclude ::-prefixed tags.

Specs (the two per .claude/rules/testing.md):
- test/01_unit/browser_engine/first_child_top_margin_collapse_spec.spl, 10 AC —
  3 reproducing, 7 generalizing, including a <li> (whose ::marker is its first
  node, so a loop that counted it could never let the real first child escape)
  and an out-of-flow first child.
- test/01_unit/browser_engine/li_marker_nth_path_key_spec.spl, 3 AC.
Sabotage: forcing the predicate false fails AC-1/2/3/8 and leaves AC-4..7 green;
swapping "::" for a prefix no tag starts with fails AC-1/2 and leaves AC-3
green. li_last_child_margin_collapse_spec stays 12/12.

Measured in ONE worktree with ONE binary per .claude/rules/testing.md
(before = the same tree with only the two lib files at HEAD~1): geometry differ
css-layout 376/359 and animation 81/79, identical on both sides — the predicate
excludes flex/grid items and padded/bordered parents, which is what those demo
pages are made of. The pixel differ could not run on this macOS host (Chrome
hits its 90s screenshot alarm on every page; one html Simple render had not
finished after 20 minutes, in BOTH lib states), so the brief's pixel stop
criterion is unevaluable this round and is not claimed either way.

Not fixed, recorded: bold advances (no static bold sans exists in-tree; the
Linux fallback paths do not exist on macOS), the <li>-reparented geometry
desync (narrowed by one step, root NOT established, two candidates named), and
tables. ifc_linebox_spec is 0/10 both before and after — pre-existing.

Test-tree divergence: check-test-tree-divergence-delta.shs origin/main..HEAD
reports PASS — 3213 pre-existing offender(s), 0 introduced by this range. The
base verdict is itself FAIL (3941 diverged vs 965 baselined, 3079 new, 103
fixed-but-still-baselined, 32 mirror-only) and is pre-existing, left by other
sessions; the offender list was saved by the helper to
/var/folders/94/j3lc49d93bx148gqls5kx5d40000gn/T//test_tree_divergence_preexisting.txt
and is recorded here as the guard's scoped-delta escape requires. This range
adds two specs under test/01_unit/browser_engine/ with no twin in test/unit/,
which the delta's own offender-list diff confirms introduces no new divergence.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TVraTPgGDVypESTsVqXPgi
@ormastes
ormastes merged commit f7b0a0c into main Sep 13, 2026
9 of 35 checks passed
@ormastes
ormastes deleted the work/web-parity-round7-2026-09-13 branch September 13, 2026 08:30
@ormastes
ormastes temporarily deployed to self-review-admission September 13, 2026 08:30 — with GitHub Actions Inactive

This branch was previously deployed

1 inactive deployment
self-review-admission — 76b7061e Deployed Sep 13, 2026 by ormastes via Invalidate changed PR self-review state #4875
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant